1. Field of the Invention
The present invention relates to computer systems capable of processing various instructions. More specifically, a system for processing saturating instructions.
2. Background
In typical computer systems, processors are implemented to operate on values represented by a large number of bits (e.g., 64) using instructions that produce one result. For example, the execution of an add instruction will add together a first 64-bit value and a second 64-bit value and store the result as a third 64-bit value. However, multimedia applications require the manipulation of large amounts of data which may be represented in a small number of bits. For example, graphical data typically requires 8 or 16 bits and sound data typically requires 8 or 16 bits. Each of these multimedia application requires one or more algorithms, each requiring a number of operations. For example, an algorithm may require an add, compare and shift operation.
To improve efficiency of multimedia applications (as well as other applications having similar characteristics), prior art processors provide packed data formats. A packed data format is one in which the bits typically used to represent a single value are broken into a number of fixed-size data elements, each of which represents a separate value. For example, a 64-bit register may be broken into two 32-bit elements, each representing a separate 32-bit value. In addition, these prior art processors provide instructions for separately manipulating each element in these packed data types in parallel. For example, a packed add instruction adds together corresponding data elements from a first packed data and a second packed data. Thus, if a multimedia algorithm requires a loop containing five operations that must be performed on a large number of data elements, it is desirable to pack the data and perform these operations in parallel using packed data instructions.
When performing operations on various data types, it may be desirable to provide saturating instructions; i.e., instructions which clamp the result of the operation when the result exceeds the range of permitted values. Clamping means forcing the operation's result to a maximum or minimum value when the result overflows or underflows the range of values permitted for the data format. In the case of underflow, saturation clamps the result to the lowest value in the range and in the case of overflow, to the highest value. The allowable ranges for various data formats are described below. Various types of saturating instructions include signed saturating addition and subtraction, unsigned saturating addition and subtraction, and greater-than comparison instructions.
Saturation instructions are particularly important in multimedia applications to provide accurate representation of audio signals, video signals, and other data. Clamping an operation's result to a maximum or minimum value prevents "wrap-around" of the resulting value. "Wrap-around" refers to the situation where the overflow or underflow generates a result which is inaccurate due to a carry into or out of the most significant bit of the result. Additional details regarding overflow and underflow are provided below. For example, if two values are added together and the result exceeds the maximum value for the data format, the result will "wrap-around" without saturation. The result generated in this example may be smaller than either of the two values added together, a clearly erroneous result. In a multimedia application, if the addition of two values results in an overflow, the result should be clamped to the maximum value (which is closer to the actual result than the "wrap-around" result).
Known systems for processing instructions utilize flags to indicate overflow or underflow conditions. These flags may include an overflow flag, an underflow flag, a carry flag, and flags indicating the type of instruction being executed. Instead of actually clamping the value of the result to a maximum or minimum, these known systems simply set an overflow/underflow flag and allow the result to "wrap-around." Therefore, these systems provide an indication of whether an overflow or underflow occurred, but do not clamp the result to an appropriate maximum or minimum value.